﻿// ## 2023/09/04 # 黑店小小二 # 修复据点显示重叠 ##
// ## 2023/05/11 # 江东新风 # 将据点正上方的信息显示均移至此处 ##

namespace BASE_ADD_INFO
{

    //---------------------------------------------------------------------------------------
    int 信息行数 = 0;
    const int 据点信息版本 = 1; // 0老版本，1新窗体版本
    const array<string> desc_148 = { "常规人口", "伤兵", "兵役人口", "预增兵役", "城墙总高","城防",  "兵装维护", "军饷支出", "金收入", "内政支出" };

    const array<string> desc2_148 = { "将军", "人口", "士兵", "月招兵量", "资金", "月金收支", "兵粮", "季粮收支" };
    // -------------------------------------------------------------------------------------------------------
    bool calc_auto_data = true; // 进入某些场景，会触发无伤病舌战，武将会变虚拟武将导致自动内政身份去除，这里加个例外

    class AutoIAinfo
    {
        pk::dialog@ dialog;
        pk::sprite9 @ dlgbg;
        pk::text @base_title = @null;

        array<pk::text @> text_title(4, null);
        array<pk::text @> text_item(7, null);
        array<pk::text @> text_person(7, null);
        array<pk::text @> text_effic(7, null);
        array<pk::text @> text_gain(7, null);

        array<pk::sprite9 @> bg_title(4, null);
        array<pk::sprite9 @> bg_item(7, null);
        array<pk::sprite9 @> bg_person(7, null);
        array<pk::sprite9 @> bg_effic(7, null);
        array<pk::sprite9 @> bg_gain(7, null);

        //色彩进度条
        pk::sprite3@ amt_siege_dir = @null;
        pk::sprite3@ amt_siege_rng = @null;
        pk::sprite3@ amt_boat = @null;
        pk::image@ img_boat = @null;

        array<string> title_str = { "项目", "武将", "开支", "产出" };
        array<string> item_str = { "征兵", "训练", "巡查", "兵装", "马匹", "攻具", "舰船" };

        void init()
        {
            @ dialog = @null;
            @ dlgbg = @null;
            @base_title = @null;
            text_title = { null,null,null,null };
            text_person = { null,null,null,null,null,null,null };
            text_effic = { null,null,null,null,null,null,null };
            text_gain = { null,null,null,null,null,null,null };

            bg_title = { null,null,null,null };
            bg_person = { null,null,null,null,null,null,null };
            bg_effic = { null,null,null,null,null,null,null };
            bg_gain = { null,null,null,null,null,null,null };

            @ amt_siege_dir = @null;
            @ amt_siege_rng = @null;
            @ amt_boat = @null;
            @ img_boat = @null;
        }
    };

    class BaseAddinfo
    {
        pk::dialog @dialog;
        pk::sprite9 @ dlgbg;
        pk::text @base_name_text;
        pk::text @policy_text;
        array<pk::sprite9 @> bbg0(11, null);
        array<pk::sprite9 @> bbg1(11, null);
        array<pk::text @> btext0(11, null);
        array<pk::text @> btext1(11, null);


        void init()
        {
            @dialog = @null;
            @dlgbg = @null;
            @base_name_text = @null;
            @policy_text = @null;
            for (int i = 0; i < 11; ++i)
            {
                @bbg0[i] = @null;
                @bbg1[i] = @null;
                @btext0[i] = @null;
                @btext1[i] = @null;
            }
        }
    };

    class Main
    {
        AutoIAinfo IA_;
        BaseAddinfo BA_;


        Main()
        {
            //dlg init相关
            pk::bind(210, pk::trigger210_t(dialog_init));//直接改成跟随dlg148初始化

            // 当鼠标放在据点上时会在上方显示据点相关信息
            pk::bind2(120, pk::trigger120_t(信息显示_据点信息), 999);

            pk::bind(220, pk::trigger220_t(BUILDING_HUD_INIT));

            pk::bind(99, pk::trigger99_t(SCENECHANGE));
            //对应信息的刷新，draw_game trigger移除，放到更合适的位置---存在异常，切换回120trigger
            //pk::bind(222, pk::trigger222_t(func_信息显示_据点信息));//显示城市
            //pk::bind(223, pk::trigger223_t(func_信息显示_地名信息));//用来封地上方信息的更新
            //pk::bind(224, pk::trigger224_t(func_信息显示_据点信息));//显示港关

        }

        void dialog_init(pk::dialog@ dlg, int dlg_id)
        {
            if (dlg_id == 148)
            {
                BAdialog_init();
                IAdialog_init();
            }
        }

        void BAdialog_init()
        {
            // 窗体初始化
            BA_.init();
            pk::size dialog_size = pk::size(358, 181);
            pk::frame @frame = pk::get_frame();
            pk::dialog @new_dialog = frame.create_dialog(false);
            @BA_.dialog = @new_dialog;
            new_dialog.set_pos(pk::get_resolution().width / 2 - dialog_size.width / 2, 5);
            new_dialog.set_size(dialog_size);
            new_dialog.set_visible(false);

            //底色背景
            pk::sprite9@ bg = new_dialog.create_sprite9(70);
            bg.set_color(0x40010101);
            bg.set_size(dialog_size);
            @BA_.dlgbg = @bg;

            pk::text @text = new_dialog.create_text();
            text.set_size(244, 24);
            text.set_pos(5, 1);
            // text.set_text(pk::encode(desc_148[i]));
            text.set_visible(true);
            text.set_text_font(FONT_BIG);
            @BA_.base_name_text = @text;

            @text = new_dialog.create_text();
            text.set_size(244, 24);
            text.set_pos(180, 1);
            // text.set_text(pk::encode(desc_148[i]));
            text.set_visible(true);
            @BA_.policy_text = @text;

            for (int i = 0; i < 10; ++i)
            {
                // 文字描述
                pk::sprite9 @bg0 = new_dialog.create_sprite9(393);
                bg0.set_size(74, 22);
                bg0.set_pos(7 + 174 * (i % 2), 5 + 26 + 24 * (i / 2));
                if (i == 10)
                    bg0.set_pos(7 + 174, 5 + 2);
                bg0.set_visible(true);
                @BA_.bbg0[i] = @bg0;

                pk::text @text0 = new_dialog.create_text();
                text0.set_size(64, 16);
                text0.set_pos(7 + 174 * (i % 2) + 5, 5 + 26 + 24 * (i / 2) + 3);
                if (i == 10)
                    text0.set_pos(7 + 174 + 5, 5 + 2 + 3);
                // text0.set_text(pk::encode(desc_148[i]));
                text0.set_visible(true);
                text0.set_text_align(TEXT_ALIGN_CENTER);
                @BA_.btext0[i] = @text0;

                // 具体数值
                pk::sprite9 @bg1 = new_dialog.create_sprite9(411);
                bg1.set_size(94, 22);
                bg1.set_pos(7 + 78 + 174 * (i % 2), 5 + 26 + 24 * (i / 2));
                if (i == 10)
                    bg1.set_pos(7 + 78 + 174, 5 + 2);
                bg1.set_visible(true);
                @BA_.bbg1[i] = @bg1;

                pk::text @text1 = new_dialog.create_text();
                text1.set_size(84, 16);
                text1.set_pos(7 + 78 + 174 * (i % 2) + 5, 5 + 26 + 24 * (i / 2) + 3);
                if (i == 10)
                    text1.set_pos(7 + 78 + 174 + 5, 5 + 2 + 3);
                text1.set_text_align(2);
                @BA_.btext1[i] = @text1;
            }
        }

        void IAdialog_init()
        {
            // 窗体初始化
            IA_.init();
            pk::size dialog_size = pk::size(360, 255);
            pk::frame @frame = pk::get_frame();
            pk::dialog @new_dialog = frame.create_dialog(false);
            @IA_.dialog = @new_dialog;
            new_dialog.set_pos(pk::get_resolution().width / 2 - dialog_size.width / 2, 275);//待调整
            new_dialog.set_size(dialog_size);
            new_dialog.set_visible(false);

            //底色背景
            pk::sprite9@ bg = new_dialog.create_sprite9(70);
            bg.set_color(0x40010101);
            bg.set_size(dialog_size);
            @IA_.dlgbg = @bg;

            //base_title
            pk::text @text = new_dialog.create_text();
            text.set_size(200, 24);
            text.set_pos(7, 5);

            text.set_visible(true);
            text.set_text_align(TEXT_ALIGN_LEFT);
            text.set_text_font(FONT_BIG);
            @IA_.base_title = @text;

            //先设置列表抬头
            for (uint i = 0; i < 4; ++i)
            {
                pk::sprite9 @bg0 = new_dialog.create_sprite9(393);
                bg0.set_size(82, 22);
                bg0.set_pos(7 + 84 * i, 5 + 26);

                bg0.set_visible(true);
                @IA_.bg_title[i] = @bg0;


                pk::text @text0 = new_dialog.create_text();
                text0.set_size(72, 16);
                text0.set_pos(7 + 84 * i + 5, 5 + 26 + 3);

                text0.set_visible(true);
                text0.set_text_align(TEXT_ALIGN_CENTER);
                @IA_.text_title[i] = @text0;
            }

            //剩下的分项目
            for (uint i = 0; i < 7; ++i)
            {
                pk::point pos = pk::point(7, 55 + 24 * i);
                if (i >= 0) pos.y += 4;
                if (i >= 3) pos.y += 4;
                if (i >= 5) pos.y += 4;
                //item
                pk::sprite9 @bg0 = new_dialog.create_sprite9(393);
                bg0.set_size(82, 22);
                bg0.set_pos(pos);//(7, 5 + 50 + 24 * i);

                bg0.set_visible(true);
                @IA_.bg_item[i] = @bg0;

                pk::text @text0 = new_dialog.create_text();
                text0.set_size(72, 16);
                text0.set_pos(pos.x + 5, pos.y + 3);// (7 + 5, 5 + 50 + 24 * i + 3);
                text0.set_text_align(TEXT_ALIGN_CENTER);
                @IA_.text_item[i] = @text0;

                pos.x += 84;
                //执行者值
                pk::sprite9 @bg1 = new_dialog.create_sprite9(411);
                bg1.set_size(82, 22);
                bg1.set_pos(pos);// (7 + 84, 5 + 50 + 24 * i);
                bg1.set_visible(true);
                @IA_.bg_person[i] = @bg1;

                pk::text @text1 = new_dialog.create_text();
                text1.set_size(72, 16);
                text1.set_pos(pos.x + 5, pos.y + 3);//(7 + 84 + 5, 5 + 50 + 24 * i + 3);
                text1.set_text_align(TEXT_ALIGN_CENTER);
                @IA_.text_person[i] = @text1;

                pos.x += 84;
                //支出值
                @bg1 = new_dialog.create_sprite9(411);
                bg1.set_size(82, 22);
                bg1.set_pos(pos);//(7 + 84 * 2, 5 + 50 + 24 * i);

                bg1.set_visible(true);
                @IA_.bg_effic[i] = @bg1;

                @text1 = new_dialog.create_text();
                text1.set_size(72, 16);
                text1.set_pos(pos.x + 5, pos.y + 3);//(7 + 84 * 2 + 5, 5 + 50 + 24 * i + 3);
                text1.set_text_align(TEXT_ALIGN_CENTER);
                @IA_.text_effic[i] = @text1;

                pos.x += 84;
                //产出值
                @bg1 = new_dialog.create_sprite9(411);
                bg1.set_size(82, 22);
                bg1.set_pos(pos);//(7 + 84 * 3, 5 + 50 + 24 * i);

                bg1.set_visible(true);
                @IA_.bg_gain[i] = @bg1;

                @text1 = new_dialog.create_text();
                text1.set_size(72, 16);
                text1.set_pos(pos.x + 5, pos.y + 3);//(7 + 84 * 3 + 5, 5 + 50 + 24 * i + 3);//
                text1.set_text_align(TEXT_ALIGN_CENTER);
                @IA_.text_gain[i] = @text1;
            }
            //色条

            pk::sprite3 @sprite = new_dialog.create_sprite3(476);//427
            auto bg_pos = IA_.bg_gain[5].get_pos();
            auto bg_size = IA_.bg_gain[5].get_size();
            sprite.set_pos(bg_pos.x, bg_pos.y + bg_size.height - 12);
            sprite.set_color(0x50CDAA7D);
            sprite.set_size(bg_size.width, 16);
            sprite.set_visible(true);
            @IA_.amt_siege_dir = @sprite;

            @sprite = new_dialog.create_sprite3(476);
            bg_pos = IA_.bg_gain[5].get_pos();
            bg_size = IA_.bg_gain[5].get_size();
            sprite.set_pos(bg_pos.x, bg_pos.y + bg_size.height - 6);
            sprite.set_color(0x50FF3030);
            sprite.set_size(bg_size.width, 16);
            sprite.set_visible(true);
            @IA_.amt_siege_rng = @sprite;

            @sprite = new_dialog.create_sprite3(476);
            bg_pos = IA_.bg_gain[6].get_pos();
            bg_size = IA_.bg_gain[6].get_size();
            sprite.set_pos(bg_pos.x, bg_pos.y + bg_size.height - 6);
            sprite.set_color(0x5087CEFA);
            sprite.set_size(bg_size.width, 16);
            sprite.set_visible(true);
            @IA_.amt_boat = @sprite;


            //分隔线
            pk::sprite0 @sprite0 = new_dialog.create_sprite0(427);
            bg_pos = IA_.bg_item[0].get_pos();
            bg_size = IA_.bg_item[0].get_size();
            sprite0.set_pos(bg_pos.x, bg_pos.y - 11);
            sprite0.set_color(0x60f5f5f5);
            sprite0.set_size(bg_size.w * 4 + 6, 16);
            sprite0.set_visible(true);

            @sprite0 = new_dialog.create_sprite0(427);
            bg_pos = IA_.bg_item[3].get_pos();
            bg_size = IA_.bg_item[3].get_size();
            sprite0.set_pos(bg_pos.x, bg_pos.y - 11);
            sprite0.set_color(0x60f5f5f5);
            sprite0.set_size(bg_size.w * 4 + 6, 16);
            sprite0.set_visible(true);
            //@IA_.amt_siege_dir = @sprite;

            @sprite0 = new_dialog.create_sprite0(427);
            bg_pos = IA_.bg_item[5].get_pos();
            bg_size = IA_.bg_item[5].get_size();
            sprite0.set_pos(bg_pos.x, bg_pos.y - 11);
            sprite0.set_color(0x60f5f5f5);
            sprite0.set_size(bg_size.w * 4 + 6, 16);
            sprite0.set_visible(true);

            //不知为何，image不显示
            //pk::image@ image = new_dialog.create_image(0);
            //image.set_z_order(999);
            //image.set_image(pk::core_dir + "data/0328/hud-1x1.png", false); // 无效pk::core_dir + "data/dahunluan.png");
            //auto pos = IA_.bg_gain[6].get_pos();
            //auto size = IA_.bg_gain[6].get_size();
            //pos.x = pos.x - 1;
            //size.w = 34;
            //image.set_pos(pos);
            //image.set_size(size);
            //pk::bgra32 color = 0xffff0000;//pk::bgra32(force_color[force_id]);//pk::bgra32(pk::get_force_color2(force_id));
            //image.set_color(color.c);

        }

        void SCENECHANGE(int cur_scene, int next_scene)
        {
            calc_auto_data = next_scene == -1;
        }

        // 显示信息
        void 信息显示_据点信息()
        {

            if (pk::is_alive(BA_.dialog, true) and BA_.dialog.is_visible())
                BA_.dialog.set_visible(false); /**/
            if (pk::is_alive(IA_.dialog, true) and IA_.dialog.is_visible())
                IA_.dialog.set_visible(false); /**/
            // 光标指的坐标
            pk::point cursor_pos = pk::get_cursor_hex_pos();
            if (!pk::is_valid_pos(cursor_pos))
                return;

            // 光标上指示的建筑物
            pk::building @building = pk::get_building(cursor_pos);
            if (building is null)
                return;

            int building_type = get_building_type(building);
            if (building_type == 0)
            {
                // pk::trace("军饷维护费");
                //  显示信息
                func_信息显示_据点信息(building);
                //if (BA_.dialog !is null) BA_.dialog.set_visible(true);
                //if (IA_.dialog !is null and ch::get_set_p(0).get_mod_set(自动内政扩展_开关)) IA_.dialog.set_visible(true);
            }
            else if (building_type == 1)
            {
                //if (BA_.dialog !is null) BA_.dialog.set_visible(true);
                func_信息显示_地名信息(building);
            }
        }

        void func_信息显示_基本据点信息(pk::building @building)
        {
            bool 测试 = true;
            if (测试)
            {
                string building_name1 = pk::get_old_base_name(building.get_id());
                string building_name2 = pk::get_new_base_name(building.get_id());
                string a = building.facility == 设施_城市 ? "城市信息(\x1b[1x{}{}\x1b[0x)" : "据点信息(\x1b[1x{}{}\x1b[0x)";
                string title = pk::format(a, building_name1, building_name2);
                int middle = int(pk::get_resolution().width) / 2;
                int left = middle - 200;
                int right = middle + 200;
                int top = 5;
                pk::draw_text(pk::encode(title), pk::point(left + 5, top + 5), 0xffffffff, FONT_BIG, 0xff000000);
            }
        }

        void func_信息显示_据点信息(pk::building @building)
        {
            // pk::draw_rect(pk::rectangle(left, top, right, bottom), 0xff00ccff);
            if (BA_.dialog is null and IA_.dialog is null) return; //没有东西需要显示，则返回
            int base_id = building.get_id();
            auto base_t = ch::get_base_p(base_id);
            auto building_p = ch::get_baseIA(base_id);

            string building_name = pk::decode(pk::get_name(building));

            string a = building.facility == 设施_城市 ? "城市信息(\x1b[1x{}\x1b[0x)" : "据点信息(\x1b[1x{}\x1b[0x)";
            string title = pk::format(a, building_name);

            int 信息行数 = 0;

            // int 总开支 = int(building_p.get_all_effic());
            // int 军饷开支 = 军饷维护费::get_军饷(building) + 军饷维护费::get_维护费(building);
            // 总开支 += 军饷开支;

            if (BA_.dialog !is null)
            {
                pk::size dialog_size = pk::size(358, (157 - (ch::get_auto_affairs_status(building) ? 0 : 24)));
                BA_.dialog.set_pos(pk::get_resolution().width / 2 - dialog_size.width / 2, 5); // 重设一下，确保分辨率不产生影响

                BA_.dlgbg.set_size(dialog_size);//pk::draw_filled_rect(pk::rectangle(pk::point(pk::get_resolution().width / 2 - dialog_size.width / 2, 5), dialog_size), ((0xff / 2) << 24) | 0x010101); //((0xff / 2) << 24) | 0x777777
                BA_.dialog.set_visible(true);
                string base_name = pk::get_name(building);
                if (building.get_id() < 据点_末)
                {
                    base_name = base_name + "(" + ch::get_level_desc(base_t.city_level) + ")";
                    BA_.policy_text.set_visible(true);
                    BA_.policy_text.set_text(pk::encode(pk::format("兵役政策:{}", ch::get_base_policy(building))));
                }
                else BA_.policy_text.set_text("");
                BA_.base_name_text.set_text(base_name);


                bool need_hide = check_force(building);


                for (int i = 0; i < 10; ++i)
                {
                    //设置文本
                    BA_.btext0[i].set_text(pk::encode(desc_148[i]));
                    BA_.btext1[i].set_text(get_base_add_info(base_id, i, need_hide));
                    //设置显示
                    bool show_widget = i > 7 and pk::is_player_controlled(building) ? ch::get_set_p(0).get_mod_set(自动内政扩展_开关) : true;
                    BA_.bbg0[i].set_visible(show_widget);
                    BA_.bbg1[i].set_visible(show_widget);
                    BA_.btext0[i].set_visible(show_widget);
                    BA_.btext1[i].set_visible(show_widget);
                }

            }

            //显示自动内政
            if (IA_.dialog !is null and ch::get_auto_affairs_status(building))
            {
                pk::size dialog_size = pk::size(360, 240);
                IA_.dialog.set_pos(pk::get_resolution().width - dialog_size.width - 10, 260); // 重设一下，确保分辨率不产生影响

                IA_.dlgbg.set_size(dialog_size);//pk::draw_filled_rect(pk::rectangle(pk::point(pk::get_resolution().width - dialog_size.width -10, 260), dialog_size), ((0xff / 2) << 24) | 0x010101); //((0xff / 2) << 24) | 0x777777
                IA_.dialog.set_visible(true);

                string base_name = pk::get_name(building);
                base_name = "自动化内政" + "(" + pk::decode(base_name) + ")";
                IA_.base_title.set_text(pk::encode(base_name));
                bool need_hide = check_force(building);

                //内容更新
                if ((pk::time()) % 10 == 1 and building.is_player() and calc_auto_data)
                {
                    内政自动::calculate_building2(building, false);
                    内政自动::重置内政官(building);
                    // pk::trace(pk::time() + "");
                }

                for (int i = 0; i < 4; ++i)
                {
                    IA_.text_title[i].set_text(pk::encode(IA_.title_str[i]));
                }

                for (int i = 0; i < 7; ++i)
                {
                    IA_.text_item[i].set_text(pk::encode(IA_.item_str[i]));
                    int person_id = building_p.get_charge(i);
                    string person_str = pk::encode("无");
                    if (pk::is_valid_person_id(person_id))
                        person_str = pk::get_name(pk::get_person(person_id));
                    IA_.text_person[i].set_text(person_str);

                    IA_.text_effic[i].set_text(pk::format("{}", building_p.get_effic(i)));
                    string gain_str = pk::format("{}", building_p.get_gain(i));
                    if (i > 4) gain_str = pk::format("{}%", building_p.get_gain(i) / 10.0f);
                    if (i == 3 or i == 5) gain_str = pk::format("{}{}", pk::encode(building_p.get_choose_name2(base_id, i)), gain_str);
                    IA_.text_gain[i].set_text(gain_str);

                    //设置不同等级的颜色
                    uint color = building_p.get_rank_color(building_p.get_stat_rank(i));
                    IA_.bg_person[i].set_color(color);
                }

                //设置进度条
                auto bg_size = IA_.bg_gain[5].get_size();
                IA_.amt_siege_dir.set_size(bg_size.width * building_p.punch / 1000, 6);
                IA_.amt_siege_rng.set_size(bg_size.width * building_p.well / 1000, 6);
                IA_.amt_boat.set_size(bg_size.width * building_p.boat / 1000, 6);

            }
        }

        void func_信息显示_地名信息(pk::building @building)
        {
            if (!pk::is_alive(building)) return;
            // 已在悬浮窗显示的信息应该不显示
            if (BA_.dialog is null) return;
            int id = ch::get_spec_id(building);
            // 地名_id = id;
            if (!ch::is_valid_spec_id(id)) return;

            int gold_income = 0;
            int food_income = 0;
            int troops_income = 0;

            auto spec_t = ch::get_spec_p(id);
            int person_id = spec_t.person;
            bool has_person = pk::is_valid_person_id(person_id);
            string person_name = ch::get_spec_person_name(id);

            // 这里的log实际上是ln,因此要换底运算一次
            float 人口系数 = float(log(spec_t.population) / log(10)) / 5.0f;

            if (has_person)
            {
                // 两者通用信息提前计算
                int city_id = pk::get_city_id(ch::get_spec_pos(id));
                auto base_t = ch::get_base_p(city_id);

                // 注:显示面板中玩家和AI是一致算法,但是AI的显示和实际数值有难度修正,隐蔽作弊.

                gold_income = inter::cal_spec_gold_income(id, base_t.base_revenue);

                // 统一算法,并且加上耗粮--耗粮不显示，应该就单纯每回合扣除，和原版一致
                food_income = inter::cal_spec_food_income(id, base_t.base_harvest);
                //food_income -= spec_t.troops / 1000 * 25;

                troops_income = inter::cal_spec_pop_troops_income(id).second;
            }

            if (BA_.dialog !is null)
            {
                int 行数 = has_person ? 4 : 1;
                pk::size dialog_size = pk::size(358, 34 + 24 * 行数);
                BA_.dialog.set_pos(pk::get_resolution().width / 2 - dialog_size.width / 2, 5); // 重设一下，确保分辨率不产生影响

                BA_.dlgbg.set_size(dialog_size); //pk::draw_filled_rect(pk::rectangle(pk::point(pk::get_resolution().width / 2 - dialog_size.width / 2, 5), dialog_size), ((0xff / 2) << 24) | 0x010101); //((0xff / 2) << 24) | 0x777777
                BA_.dialog.set_visible(true);

                string title = pk::format("{}(主城:{})", ch::get_spec_name(id), pk::decode(pk::get_name(pk::get_building(pk::get_building_id(building.get_pos())))));

                BA_.base_name_text.set_text(pk::encode(title));
                BA_.policy_text.set_visible(false);
                bool need_hide = check_force(building);

                // 显示信息： 将军 人口 兵力 招兵量 资金 金收支 兵粮 粮收支

                for (int i = 0; i < 8; ++i)
                {
                    if (!has_person and i > 1)
                    {
                        BA_.bbg0[i].set_visible(false);
                        BA_.btext0[i].set_visible(false);
                        BA_.bbg1[i].set_visible(false);
                        BA_.btext1[i].set_visible(false);
                    }
                    else
                    {
                        BA_.bbg0[i].set_visible(true);
                        BA_.btext0[i].set_visible(true);
                        BA_.bbg1[i].set_visible(true);
                        BA_.btext1[i].set_visible(true);
                        BA_.btext0[i].set_text(pk::encode(desc2_148[i]));
                    }
                }
                for (int i = 8; i < 10; ++i)
                {
                    BA_.bbg0[i].set_visible(false);
                    BA_.btext0[i].set_visible(false);
                    BA_.bbg1[i].set_visible(false);
                    BA_.btext1[i].set_visible(false);
                }

                BA_.btext1[0].set_text(need_hide ? "***" : pk::format("{}", person_name));
                BA_.btext1[1].set_text(need_hide ? "***" : pk::format("{}", spec_t.population));

                if (has_person)
                {
                    BA_.btext1[2].set_text(need_hide ? "***" : pk::format("{}", spec_t.troops));
                    BA_.btext1[3].set_text(need_hide ? "***" : pk::format("{}", troops_income));
                    BA_.btext1[4].set_text(need_hide ? "***" : pk::format("{}", spec_t.gold));
                    BA_.btext1[5].set_text(need_hide ? "***" : pk::format("{}", gold_income));
                    BA_.btext1[6].set_text(need_hide ? "***" : pk::format("{}", spec_t.food));
                    BA_.btext1[7].set_text(need_hide ? "***" : pk::format("{}", food_income));
                }
            }
        }

        string get_base_add_info(int base_id, int type, bool need_hide)
        {
            auto base_t = ch::get_base_p(base_id);
            auto building_p = ch::get_baseIA(base_id);
            auto base = pk::get_building(base_id);
            float rate;

            if (need_hide) return pk::encode("***");

            string str = "";
            switch (type)
            {
                case 0:
                    str = pk::format("{}", base_t.population);
                    rate = float(人口系统::main.pop_gain_calc[base_id]) / base_t.population;
                    if (rate > 0.002) str = pk::format("{}\x1b[1x{}", base_t.population, pk::encode("↑↑"));
                    else if (rate >= 0) str = pk::format("{}\x1b[1x{}", base_t.population, pk::encode("↑"));
                    else if (rate < -0.0035) str = pk::format("{}\x1b[16x{}", base_t.population, pk::encode("↓↓"));
                    else if (rate < -0.002) str = pk::format("{}\x1b[16x{}", base_t.population, pk::encode("↓"));
                    // str = pk::format("{}", 人口系统::main.pop_gain_calc[base_id]);

                    break;
                case 1:
                    str = pk::format("{}", base_t.wounded);
                    break;
                case 2:
                    str = pk::format("{}", base_t.mil_pop_all);
                    break;
                case 3:
                    str = pk::format("\x1b[28x{}\x1b[0x/{}", base_t.mil_pop_av, pk::encode("月"));
                    break;
                case 4:
                    str = pk::format("{}+\x1b[1x{}", batt::get_building_height(base), pk::min(building_p.city_defense, 3000) / 100 + (base.has_tech(技巧_城壁强化) ? batt::强化防卫_高度加成 : 0));
                    break;
                case 5:
                    str = pk::format("{}+\x1b[1x{}\x1b[0x", base.hp, building_p.city_defense);
                    break;
                case 6:
                    str = pk::format("\x1b[28x{}\x1b[0x/{}", 军饷维护费::get_维护费(base), pk::encode("旬"));
                    break;
                case 7:
                    str = pk::format("\x1b[28x{}\x1b[0x/{}", 军饷维护费::get_军饷(base), pk::encode("旬"));
                    break;
                case 8:
                    str = pk::format("\x1b[28x{}\x1b[0x/{}", base_t.base_revenue, pk::encode("月"));
                    break;
                case 9:
                    str = pk::format("\x1b[28x{}\x1b[0x/{}", int(building_p.get_all_effic()), pk::encode("旬"));
                    break;
                default:
                    break;
            }
            return str;
        }
        //-1非建筑，0 城港关，1 郡县， 2 其他
        int get_building_type(pk::building @building)
        {
            int building_id = building.get_id();
            if (pk::is_valid_base_id(building_id))
                return 0;
            int spec_id = ch::to_spec_id(building_id);
            if (ch::is_valid_spec_id(spec_id))
                return 1;
            // 地名_id = id;
            //  pk::trace(pk::format("地名id:{}", id));
            // func_信息显示_基本据点信息(building);

            return 2;
        }

        bool check_force(pk::building @building)
        {
            if (pk::get_scenario().difficulty < 难易度_超级)
                return false;
            if (building.is_player())
                return false;
            if (pk::is_player_controlled(building))
                return false;
            if (building.get_force_id() == pk::get_current_turn_force_id())
                return false;
            return true;
        }

        void BUILDING_HUD_INIT(pk::building@ building, pk::hud_container@ hud_container)
        {
            int force_id = building.get_force_id();
            if (pk::is_valid_force_id(force_id))
            {
                // find_child 
                pk::hud@ bg = hud_container.find_child(2893);

                if (bg !is null)
                    ch::add_force_color(hud_container, bg, pk::get_force(force_id).color);
            }
        }

    }

    Main main;

}
